package br.com.automed.entity;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name="CM_CONVENIO")
@NamedQueries({
	@NamedQuery(name="listarConvenio", query="from Convenio c order by c.convenio")
})
public class Convenio {
	
	public static final String NAMED_QUERY_LIST_CONVENIO = "listarConvenio";
	
	@Id
    @GeneratedValue(generator = "system-uuid", strategy=GenerationType.AUTO)
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    @Column(name = "ID_CONVENIO")
	private String idConvenio;
	
	@Column(name = "ST_CONVENIO")
	private String convenio;
	
	@OneToMany(mappedBy="convenio")
	private List<Paciente> pacientes;

	@OneToMany(mappedBy="convenio")
	private List<MatriculaValida> matriculas;

	@OneToMany(mappedBy="convenio")
	private List<Consulta> consultas;
	
	public Convenio() {
	}

	public Convenio(String idConvenio, String convenio) {
		this.idConvenio = idConvenio;
		this.convenio = convenio;
	}	
	
	public String getIdConvenio() {
		return idConvenio;
	}

	public void setIdConvenio(String idConvenio) {
		this.idConvenio = idConvenio;
	}

	public String getConvenio() {
		return convenio;
	}

	public void setConvenio(String convenio) {
		this.convenio = convenio;
	}

	public List<Paciente> getPacientes() {
		return pacientes;
	}

	public void setPacientes(List<Paciente> pacientes) {
		this.pacientes = pacientes;
	}

	public List<MatriculaValida> getMatriculas() {
		return matriculas;
	}

	public void setMatriculas(List<MatriculaValida> matriculas) {
		this.matriculas = matriculas;
	}

	public List<Consulta> getConsultas() {
		return consultas;
	}

	public void setConsultas(List<Consulta> consultas) {
		this.consultas = consultas;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((idConvenio == null) ? 0 : idConvenio.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Convenio other = (Convenio) obj;
		if (idConvenio == null) {
			if (other.idConvenio != null)
				return false;
		} else if (!idConvenio.equals(other.idConvenio))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		
		return this.idConvenio + ";" + this.convenio;
	}
}
